/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.game.room.handler;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import extension.game.room.RoomExtension;
import extension.game.room.Game;
import extension.game.room.Player;
import extension.game.room.GameResponse;

/**
 *
 * @author daz
 */
public class PlayerCountHandler extends BaseClientRequestHandler {

    @Override
    public void handleClientRequest(User user, ISFSObject params) {
        RoomExtension phomExtension = (RoomExtension) getParentExtension();
        Game game = phomExtension.getGame();
        Player[] listPlayer = game.getListPlayers();
        GameResponse response = phomExtension.getResponse();
        if (!game.getIsPlay()) {
            for (int i = 0; i < game.getMaxPlayer(); i++) {
                if (listPlayer[i] != null && listPlayer[i].getName().equals(user.getName())) {
                    response.sendPlayerCount(listPlayer[i].getSeatPos());
                    break;
                }
            }
        }
    }
}
